package com.ymatou.iapi.activitymanage.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.activitymanage.parameter.activityExpiredReturnStockBean;
import com.ymatou.iapi.activitymanage.service.activityExpiredReturnStockCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.YmtActivityStock;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductsInActivity;
import com.ymttest.database.sqlwapper.YmtActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*活动结束返库存
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_activityExpiredReturnStock{
	private static activityExpiredReturnStockBean bean;
	private static activityExpiredReturnStockCall call;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	
	private YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
	private static YmtProductActivityStockWapper productActStockWapper=new YmtProductActivityStockWapper();
	private static YmtProductsInActivityWapper productInActivityWapper=new YmtProductsInActivityWapper();
	YmtActivityStockWapper ymtActivityStockWapper=new YmtActivityStockWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("活动结束返库存");
	}

	@Before
	public void caseUp() {
		bean=new activityExpiredReturnStockBean();
		call=new activityExpiredReturnStockCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_activityExpiredReturnStock_001() {
		Logger.start(true,"正例-活动结束返库存-结束后 不是继续 报名");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			//createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			//String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivityV3(productId,aids.get(0),true,300);	
			
			//返回库存之前
			//规格数量
		    List<YmtCatalogsI> catalogsList1 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps1=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList1.get(0).getiNum(), "验证返库存之前 规格1数量");
		    Logger.verifyEquals(900, catalogsList1.get(1).getiNum(), "验证返库存之前 规格2数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(0).get("iStockNum").toString()), "验证 返库存之前 活动库存iStockNum1数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(1).get("iStockNum").toString()), "验证返库存之前 活动库存iStockNum2数量");
		    
			Logger.comment("productId:"+productId);
			Logger.comment("activityId:"+activityId);
			
			Thread.sleep(15000);
			call.setData(bean);
			call.callService();		

			//查询消息总线
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("return_stock_"+productsInActivity.getIproductinactivityid(),"return_product_stock");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);
			//返库存之后
			//规格数量
		    List<YmtCatalogsI> catalogsList2 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps2=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(1000, catalogsList2.get(0).getiNum(), "验证返库存之后 规格1数量");
		    Logger.verifyEquals(1000, catalogsList2.get(1).getiNum(), "验证返库存之后  规格2数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(0).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum1数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(1).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum2数量");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_activityExpiredReturnStock_002() {
		Logger.start(true,"正例-活动结束返库存-结束后 继续 报名-活动库存一件都没有卖出，并且数量一样，都是报名的数量");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			//createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			//String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivityV3(productId,aids.get(0),true,300);	
			
			//返回库存之前
			//规格数量
		    List<YmtCatalogsI> catalogsList1 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps1=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList1.get(0).getiNum(), "验证返库存之前 规格1数量");
		    Logger.verifyEquals(900, catalogsList1.get(1).getiNum(), "验证返库存之前 规格2数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(0).get("iStockNum").toString()), "验证 返库存之前 活动库存iStockNum1数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(1).get("iStockNum").toString()), "验证返库存之前 活动库存iStockNum2数量");
			//Ymt_ProductsInActivity 商品在活动中的库存
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			productsInActivity.setIsRenewalApply(true);
		    //继续报名活动 IsRenameApply=1 
		    productInActivityWapper.updateByPrimaryKey(productsInActivity);
		    
			Logger.comment("productId:"+productId);
			Logger.comment("activityId:"+activityId);	
			Thread.sleep(15000);
			call.setData(bean);
			call.callService();		

			//查询消息总线
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("return_stock_"+productsInActivity.getIproductinactivityid(),"return_product_stock");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);
			//返库存之后
			//规格数量
		    List<YmtCatalogsI> catalogsList2 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps2=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(1000, catalogsList2.get(0).getiNum(), "验证返库存之后 规格1数量");
		    Logger.verifyEquals(1000, catalogsList2.get(1).getiNum(), "验证返库存之后  规格2数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(0).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum1数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(1).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum2数量");
			
		    //ymtActivityStockWapper
		    List<YmtActivityStock>  activityStocks=ymtActivityStockWapper.selectByProductId(productId).stream().filter(a->a.getStoreType().equals(0)).collect(Collectors.toList());
		    Logger.verifyEquals(100, activityStocks.get(0).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
		    Logger.verifyEquals(100, activityStocks.get(1).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_activityExpiredReturnStock_003() {
		Logger.start(true,"正例-活动结束返库存-结束后 继续 报名-活动库存两个规格卖的数量不一致");
		try {
			//续报名 先把剩余数量返回给ymt_catalogs,等续保通过后，ymt_catalogs减掉活动报名的数量，ymt_productActivityStock 中的iNum=报名数
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			//createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			//String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivityV3(productId,aids.get(0),true,300);	
			
			//返回库存之前
			//规格数量
		    List<YmtCatalogsI> catalogsList1 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps1=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList1.get(0).getiNum(), "验证返库存之前 规格1数量");
		    Logger.verifyEquals(900, catalogsList1.get(1).getiNum(), "验证返库存之前 规格2数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(0).get("iStockNum").toString()), "验证 返库存之前 活动库存iStockNum1数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(1).get("iStockNum").toString()), "验证返库存之前 活动库存iStockNum2数量");
		    
			//Thread.sleep(15000);
			//Ymt_ProductsInActivity 商品在活动中的库存
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			productsInActivity.setIsRenewalApply(true);
		    //继续报名活动 IsRenameApply=1 
		    productInActivityWapper.updateByPrimaryKey(productsInActivity);
		    
		    //参加活动之后库存剩余2
		    Map map=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId)).get(0);
		  //  productActStockWapper.updateStockByActivityIdAndProductId(productId, activityId, 2);
		    productActStockWapper.updateiStockNumByProductActivityStockId(map.get("sProductActivityStockID").toString(), 2);
		    
			Logger.comment("productId:"+productId);
			Logger.comment("activityId:"+activityId);	
			
			Thread.sleep(15000);
			call.setData(bean);
			call.callService();		

			//查询消息总线
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("return_stock_"+productsInActivity.getIproductinactivityid(),"return_product_stock");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);	
			
			//返库存之后
			//规格数量
		    List<YmtCatalogsI> catalogsList2 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps2=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(902, catalogsList2.get(0).getiNum(), "验证返库存之后 规格1数量");
		    Logger.verifyEquals(1000, catalogsList2.get(1).getiNum(), "验证返库存之后  规格2数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(0).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum1数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(1).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum2数量");
			
		    //ymtActivityStockWapper
		    List<YmtActivityStock>  activityStocks=ymtActivityStockWapper.selectByProductId(productId).stream().filter(a->a.getStoreType().equals(0)).collect(Collectors.toList());
		    Logger.verifyEquals(2, activityStocks.get(0).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
		    Logger.verifyEquals(100, activityStocks.get(1).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_activityExpiredReturnStock_004() {
		Logger.start(true,"正例-活动结束返库存-结束后 继续 报名-活动库存全都售完，重新报名活动无效");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			//createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			//String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivityV3(productId,aids.get(0),true,300);	
			
			//返回库存之前
			//规格数量
		    List<YmtCatalogsI> catalogsList1 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps1=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList1.get(0).getiNum(), "验证返库存之前 规格1数量");
		    Logger.verifyEquals(900, catalogsList1.get(1).getiNum(), "验证返库存之前 规格2数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(0).get("iStockNum").toString()), "验证 返库存之前 活动库存iStockNum1数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(1).get("iStockNum").toString()), "验证返库存之前 活动库存iStockNum2数量");
		    
			//Thread.sleep(15000);
			//Ymt_ProductsInActivity 商品在活动中的库存
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			productsInActivity.setIsRenewalApply(true);
		    //继续报名活动 IsRenameApply=1 
		    productInActivityWapper.updateByPrimaryKey(productsInActivity);
		    
		    //参加活动之后库存剩余2
		    List<Map> maplst=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		  //  productActStockWapper.updateStockByActivityIdAndProductId(productId, activityId, 2);
		    productActStockWapper.updateiStockNumByProductActivityStockId(maplst.get(0).get("sProductActivityStockID").toString(), 0);
		    productActStockWapper.updateiStockNumByProductActivityStockId(maplst.get(1).get("sProductActivityStockID").toString(), 0);
		    
			
			Logger.comment("productId:"+productId);
			Logger.comment("activityId:"+activityId);
			
			Thread.sleep(15000);
			call.setData(bean);
			call.callService();		

			//查询消息总线
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("return_stock_"+productsInActivity.getIproductinactivityid(),"return_product_stock");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);	

			//返库存之后
			//规格数量
		    List<YmtCatalogsI> catalogsList2 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps2=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList2.get(0).getiNum(), "验证返库存之后 规格1数量");
		    Logger.verifyEquals(900, catalogsList2.get(1).getiNum(), "验证返库存之后  规格2数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(0).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum1数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(1).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum2数量");
		    
		    //ymtActivityStockWapper
		    List<YmtActivityStock>  activityStocks=ymtActivityStockWapper.selectByProductId(productId).stream().filter(a->a.getStoreType().equals(0)).collect(Collectors.toList());
		    Logger.verifyEquals(0, activityStocks.size(), "验证返库存之后  重新报名活动无效");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_activityExpiredReturnStock_005() {
		Logger.start(true,"正例-活动结束返库存-结束后 继续 报名-活动库存一个规格卖完，一个规格未卖完,重新报名活动有效");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			//createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
			//String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivityV3(productId,aids.get(0),true,300);	
			
			//返回库存之前
			//规格数量
		    List<YmtCatalogsI> catalogsList1 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps1=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList1.get(0).getiNum(), "验证返库存之前 规格1数量");
		    Logger.verifyEquals(900, catalogsList1.get(1).getiNum(), "验证返库存之前 规格2数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(0).get("iStockNum").toString()), "验证 返库存之前 活动库存iStockNum1数量");
		    Logger.verifyEquals(100, Integer.parseInt(maps1.get(1).get("iStockNum").toString()), "验证返库存之前 活动库存iStockNum2数量");
		    
			//Thread.sleep(15000);
			//Ymt_ProductsInActivity 商品在活动中的库存
			YmtProductsInActivity  productsInActivity=productInActivityWapper.selectAllByiActivityId(activityId).get(0);
			productsInActivity.setIsRenewalApply(true);
		    //继续报名活动 IsRenameApply=1 
		    productInActivityWapper.updateByPrimaryKey(productsInActivity);
		    
		    //参加活动之后库存剩余2
		    List<Map> maplst=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		  //  productActStockWapper.updateStockByActivityIdAndProductId(productId, activityId, 2);
		    productActStockWapper.updateiStockNumByProductActivityStockId(maplst.get(0).get("sProductActivityStockID").toString(), 0);
		   // productActStockWapper.updateiStockNumByProductActivityStockId(maplst.get(1).get("sProductActivityStockID").toString(), 0);
		    
			
			Logger.comment("productId:"+productId);
			Logger.comment("activityId:"+activityId);
			
			Thread.sleep(15000);
			call.setData(bean);
			call.callService();		

			//查询消息总线
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("return_stock_"+productsInActivity.getIproductinactivityid(),"return_product_stock");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);	
	
			//返库存之后
			//规格数量
		    List<YmtCatalogsI> catalogsList2 = CIWapper.selectCatalogsByProductId(productId);
            //Ymt_ProductActivityStock
		    List<Map> maps2=productActStockWapper.selectAllBy(MapUtil.hashMap("sproductid",productId,"iactivityid",activityId));
		    
		    Logger.verifyEquals(900, catalogsList2.get(0).getiNum(), "验证返库存之后 规格1数量");
		    Logger.verifyEquals(1000, catalogsList2.get(1).getiNum(), "验证返库存之后  规格2数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(0).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum1数量");
		    Logger.verifyEquals(0, Integer.parseInt(maps2.get(1).get("iStockNum").toString()), "验证返库存之后  活动库存iStockNum2数量");
			
		    //ymtActivityStockWapper
		    List<YmtActivityStock>  activityStocks=ymtActivityStockWapper.selectByProductId(productId).stream().filter(a->a.getStoreType().equals(0)).collect(Collectors.toList());
		    Logger.verifyEquals(100, activityStocks.get(0).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
		    Logger.verifyEquals(100, activityStocks.get(1).getActivityStockNum(), "验证返库存之后  活动库存ActivityStockNum数量");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}